/*
 * @Author: wangjunwj wangjunwj@dinglicom.com
 * @Date: 2025-04-01 09:21:20
 * @LastEditors: cx19940809
 * @LastEditTime: 2025-04-16 10:26:45
 * @FilePath: /leosmart/src/pages/common/General/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React from 'react';
import {Alert, View} from 'react-native';
import {useTranslation} from 'react-i18next';
import {useNavigation} from '@react-navigation/native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {userApi} from '@/services/api';
import eventBus from '@/utils/eventBus';
import toast from '@/utils/toast';
import {Button, Cell, useAppTheme} from 'tsun-smart-ui';
import Logo from '@/components/Logo';

const FeatureList = () => {
  const theme = useAppTheme();
  const navigation = useNavigation();
  const {t} = useTranslation();
  const {bottom} = useSafeAreaInsets();
  const onLanguagePress = () => {
    navigation.navigate('LanguageSettings');
  };
  const onVendorPress = () => {
    navigation.navigate('InstCode');
  };
  const onCancelAccountPress = () => {
    Alert.alert(t('message.box.title'), t('common.cancel_accout'), [
      {
        text: t('user.logOutCancel'),
        style: 'cancel',
      },
      {
        text: t('common.confirmButtonText'),
        onPress: () => {
          userApi.cancel().then(res => {
            if (res.code === 0) {
              eventBus.emit('LOGOUT_REQUIRED');
              toast.success({
                message: t('common.optSuccessText'),
              });
            }
          });
        },
        style: 'destructive',
      },
    ]);
  };
  return (
    <View
      className="pt-4 mx-4 flex-1 justify-between"
      style={{
        paddingBottom: bottom + 27,
      }}>
      <View className="  bg-background-0  rounded-lg">
        <Cell
          size="large"
          data={[
            {
              title: t('settings.language'),
              left: size => {
                return (
                  <Logo
                    name="lng"
                    containerSize={size}
                    size={18}
                    backgroundColor={theme.colors?.brand?.primaryLight!}
                    color={theme.colors?.brand?.primary!}
                  />
                );
              },
              onPress: onLanguagePress,
            },
            {
              title: t('settings.supplier.installer'),
              description: t('settings.replaceinstaller'),
              left: size => {
                return (
                  <Logo
                    name="installer"
                    containerSize={size}
                    size={18}
                    backgroundColor={theme.colors?.brand?.primaryLight!}
                    color={theme.colors?.brand?.primary!}
                  />
                );
              },
              onPress: onVendorPress,
            },
          ]}></Cell>
      </View>
      <Button
        onPress={onCancelAccountPress}
        textStyle={{
          color: theme.colors?.error?.primary,
        }}
        style={{
          backgroundColor: theme.colors?.neutral?.white,
          borderRadius: 10,
        }}
        title={t('label.cancel_account')}></Button>
    </View>
  );
};

export default FeatureList;
